*Replication file for:
*"If You Insist... Identity and Interim Appointments on Elected State Supreme Courts"
*State Politics & Policy Quarterly
*Shane A. Gleason & Marigail G. Reyna
*contact author: Shane A. Gleason (shane.gleason@trincoll.edu)

*Analysis conducted in Stata 19.5 on MacOS 15.7.1


*If not already installed, you will need the combomarginsplot package
*"uncomment" the following line if you need to install combomarginsplot
*ssc install combomarginsplot


*Load the data: You may need to change the file path to match your computer.			
use gleason_reyna_justice_level.dta, clear


*Table 1: State Supreme Court Jurists by Initial Path to Bench
	*All jurists
	tab init_appointed 
	*White
	tab init_appointed if white==1 
	*White men
	tab init_appointed if whiteman==1 
	*White women
	tab init_appointed if whitewoman==1 
	*Blacks
	tab init_appointed if black==1
	*Black men
	tab init_appointed if blackmen==1 
	*Black women
	tab init_appointed if blackwoman==1 
	*Hispanics
	tab init_appointed if hispanic==1 
	*Hispanic men
	tab init_appointed if hispanic_men==1
	*Hispanic women
	tab init_appointed if latina==1 
	*All Intersectional women
	tab init_appointed if intersectional==1 
	*Asian Americans
	tab init_appointed if asian==1
	*Native Americans
	tab init_appointed if native==1


*Table 2
	*Each of the columns in Table 2 is denoted below in the numbered lines & the column header.

		*1 Whites
		logit white i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed profscore          number_justices  part_elect         prev_judge prev_pros     , cluster(state_52) 
		est sto m_white

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(white_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(white_rest, replace)
				margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(white_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc

		*2 Blacks
		logit black i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed profscore          number_justices  part_elect         prev_judge prev_pros vac_black thomas  previous_black   , cluster(state_52) 
		est sto m_black
			
			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(black_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) 	saving(black_rest, replace)
				margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(black_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc


		*3 Men
		logit male i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed profscore          number_justices  part_elect        prev_judge prev_pros   , cluster(state_52) 
		est sto m_men

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(m_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(m_rest, replace)
				margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(m_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc
		*4 Women
		logit female i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed  profscore          number_justices  part_elect        prev_judge prev_pros vac_female   oconnor previous_female female_gov , cluster(state_52) 
		est sto m_women

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(w_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(w_rest, replace)
			margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(w_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc
		*5 White men
		logit whiteman i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##init_appointed  profscore          number_justices  part_elect      prev_judge prev_pros     , cluster(state_52) 
		est sto m_whitemen

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(wm_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(wm_rest, replace)
				margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(wm_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc				
		*6 Black men
		logit blackmen i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed  profscore          number_justices  part_elect        prev_judge prev_pros vac_black_men  thomas previous_black_male female_gov    , cluster(state_52) 
		est sto m_blackmen	
			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(bm_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(bm_rest, replace)
			margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(bm_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc
		*7 White women
		logit whitewoman i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed profscore          number_justices  part_elect         prev_judge prev_pros vac_white_woman   oconnor female_gov  previous_white_female  , cluster(state_52) 
		est sto m_whitewomen

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(ww_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(ww_rest, replace)
			margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(ww_enter, replace)
		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc			
			
		*8 Intersectional women
		logit intersectional i.democratic_gov##i.init_appointed i.democratic_gov##i.unrestrained1 c.yearenter##i.init_appointed profscore          number_justices  part_elect         prev_judge prev_pros vac_intersectional   sotomayor previous_xt female_gov  , cluster(state_52) 
		est sto m_intersectional

			margins, dydx(init_appointed) at(democratic_gov=(0 1)) saving(xt_appt, replace)
			margins, dydx(democratic_gov) at(unrestrained1=(0 1)) saving(xt_rest, replace)
			margins, dydx(init_appointed) at(yearenter=(1980 1990 2000 2010 2020 )) saving(xt_enter, replace)

		*Getting AIC & BIC
		estat ic
		*Area under ROC
		lroc
*Getting that figure right
cd "/Users/sgleason/Dropbox/papers/latina_judges/stat_output/"	

esttab m_white m_black m_men m_women m_whitemen m_blackmen m_whitewomen m_intersectional using mfinals_UPDATES.tex, label star(* 0.10 ** 0.05 *** 0.01) se(3) obslast scalar(F) b(3) 
			
			
*Figure 1: % non-traditional jurists in Electoral States, 1979-2023
		*This figure requires a collapsed dataset--- it is listed at the ene of 
		*of the replication file to allow for a smooth flow from the models to 
		*their associated figures.

*Figure 2: Appointment of Jurists by Identity by Gubernatorial Party, 1980-2023
combomarginsplot white_appt black_appt  m_appt w_appt, labels ("White" "African American" "Men"  "Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45) )  


*Figure 3: Appointment of Jurists by Identity by Gubernatorial Party, 1980-2023
	combomarginsplot wm_appt bm_appt ww_appt xt_appt, labels ("White Men" "African American Men" "White Women" "Intersectional Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45)) 


*Figure 4: Appointment of Jurists by Democratic Governors Under Nomination Constraints, 1980-2023
	combomarginsplot white_rest black_rest  m_rest w_rest, labels ("White" "African American" "Men"  "Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45) ) 


*Figure 5: Appointment of Jurists by Democratic Governors Under Nomination Constraints, 1980-2023
	combomarginsplot wm_rest bm_rest ww_rest xt_rest, labels ("White Men" "Black Men" "White Women" "Intersectional Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45)) 


*Figure 6: Appointment of Jurists by Identity Over Time, 1980-2023
	combomarginsplot white_enter black_enter  m_enter w_enter, labels ("White" "African American" "Men"  "Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45)) ciopts(recast(rline)) 


*Figure 7: Appointment of Jurists by Identity Over Time, 1980-2023
	combomarginsplot wm_enter bm_enter ww_enter xt_enter, labels ("White Men" "Black Men" "White Women" "Intersectional Women") yline(0) by(_filenumber) scheme(s1mono)  xlabel(,labsize(tiny) angle(45)) ciopts(recast(rline)) 


*Figure 1 (from above)
*Load the data: You may need to change the file path to match your computer.			
	use gleason_reyna_court_level.dta, clear
twoway (line avg_pct_female year, sort) (line avg_pct_minority year, sort) (line avg_pct_intersectional year, sort) if  electoral_state==1

	
*Appendix B
*Load the data: You may need to change the file path to match your computer.			
	use gleason_reyna_court_level.dta, clear

twoway (line avg_pct_female year, sort) (line avg_pct_minority year, sort) (line avg_pct_intersectional year, sort) if  electoral_state==0





